<!DOCTYPE html>
<html>
<script src="../../../../resources/js-test.js"></script>

<style type="text/css">
::-webkit-scrollbar {
    width: 0px;
    height: 0px;
}

div { 
    line-height: 100px;
}

#hoverme { 
    background-color: lightblue;
}

#clickme { 
    background-color: lightgreen;
}

#dontclickme {
    background-color: yellow;
    display: none; 
}

#hoverme:hover #dontclickme { 
    display: block;
}
</style>

<body style="margin:0">

<div id='hoverme'>Hover over me
  <div id='dontclickme'>Don't click me</div>
</div>
<div id='clickme'>Click me</div>

<p id="description"></p>
<p>See https://bugs.webkit.org/show_bug.cgi?id=103283 for details.</p>

<div id="console"></div>

<script>
description("Tests that hover effects from a gesture tap down can be cleared by a gesture tap or mousemove outside of the hovered element.");

var clickMe = document.getElementById('clickme');
var dontClickMe = document.getElementById('dontclickme');

function runTests()
{
    if (!window.eventSender) {
        debug('This test requires DRT.');
        return;
    }

    if (!eventSender.gestureShowPress || !eventSender.gestureTap || !eventSender.mouseMoveTo) {
        debug('GestureShowPress, GestureTap, or MouseMoveTo is not supported by this platform');
        return;
    }

    debug("The Don't Click Me div should not be visible.");
    shouldBe("dontClickMe.offsetTop", "0");

    debug("The Don't Click Me div should be visible after a GestureShowPress on the Hover Over Me div.");
    shouldBe(document.elementFromPoint(50, 50).id, "hoverme");
    eventSender.gestureShowPress(50, 50);
    shouldBe("dontClickMe.offsetTop", "100");

    debug("The Don't Click Me div should not be visible after a GestureTap on the Click Me div.");
    shouldBe(document.elementFromPoint(250, 250).id, "clickme");
    eventSender.gestureTap(250, 250);
    waitUntilActiveCleared();
}

function waitUntilActiveCleared()
{
    if (dontClickMe.offsetTop != 0) {
        return setTimeout(waitUntilActiveCleared, 10);
    }

    shouldBe("dontClickMe.offsetTop", "0");

    debug("The Don't Click Me div should be visible after a GestureShowPress on the Hover Over Me div.");
    shouldBe(document.elementFromPoint(50, 50).id, "hoverme");
    eventSender.gestureShowPress(50, 50);
    shouldBe("dontClickMe.offsetTop", "100");

    debug("The Don't Click Me div should not be visible after a mouse move to below the Click Me div.");
    eventSender.mouseMoveTo(350, 350);
    shouldBe("dontClickMe.offsetTop", "0");

    finishJSTest();
}

if (window.testRunner) {
    window.jsTestIsAsync = true;
    testRunner.waitUntilDone();
}

runTests();
</script>
</body>
</html>
